package com.purong.purong.util;

import android.provider.Telephony;
import android.util.Log;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by wenjiezeng on 2017/10/12.
 */
public class ComputeUtil {
    //还款金额计算
    public static String calculate(double money,double day,double interestRate) {
        double interest=money*day*interestRate/1000+money;
        BigDecimal b = new BigDecimal(interest);
        DecimalFormat df = new DecimalFormat("##0.00");
        return df.format(b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());

    }

    //银行贷利息计算
    public static String bankLoanRate(double money, double maxRate, int month) {
        double monthRepay=money/month;
        double rate=0;
        for (int i = 0; i <month ; i++) {
            rate+=(money-monthRepay*i)*maxRate/100;
        }
        BigDecimal b = new BigDecimal(rate);
//        DecimalFormat df = new DecimalFormat("##0.0");
        DecimalFormat df = new DecimalFormat("##0");

        return df.format(b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());

    }
    public static String bankLoanFee(double money, double maxFee, int month) {
        double fee=money*maxFee/100*month;
        BigDecimal b = new BigDecimal(fee);
        DecimalFormat df = new DecimalFormat("##0");
        return df.format(b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());

    }
    public static String bankLoanOneTime(double money, double nonrecurringRate) {
        double onetime=money*nonrecurringRate/100;
        BigDecimal b = new BigDecimal(onetime);
        DecimalFormat df = new DecimalFormat("##0");
        return df.format(b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());

    }

    //小贷利息计算
    public static String smallLoanRate(int money, double rate, int month) {
        double totalRate=money*(rate/100)*month;
        BigDecimal b = new BigDecimal(totalRate);
        DecimalFormat df = new DecimalFormat("##0");
        return df.format(b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());

    }
}
